package com.wdh.kjs.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.wdh.kjs.R;
import com.wdh.kjs.http.Httpurl;
import com.wdh.kjs.model.JsonModel;
import com.wdh.kjs.model.JsonModel_my;
import com.wdh.kjs.util.DateUtilChange;
import com.wdh.kjs.util.ToastUtils;

import java.util.HashMap;

/**
 * Created by CQH on 2016/4/21.
 */
public class MessageDetailsActivity extends BaseTopActivity implements View.OnClickListener {
    private HashMap<String, String> maps = new HashMap<String, String>();
    private Intent intent;
    private TextView tv_message_detail_title;
    private TextView tv_message_detail_sender;
    private TextView tv_message_detail_time;
    private TextView tv_message_detail_context;
    private String userReceiveMessageId;
    private JsonModel_my jsonModel_my;
    protected LinearLayout ll_topBack;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_message_detail);
        userReceiveMessageId = getIntent().getStringExtra("userReceiveMessageId");
        initTopBar("消息详情");
        initview();
        intweb();
        setRead();
    }

    private void intweb() {
        RequestParams params = new RequestParams();
        params.addBodyParameter("userReceiveMessageId", userReceiveMessageId);

        HttpUtils http = new HttpUtils();
        http.send(HttpRequest.HttpMethod.POST, Httpurl.URL_STSTION_MESSAGE_DETAIL, params, new RequestCallBack<String>() {

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                Gson gson = new Gson();
                jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);
                if (jsonModel_my.success) {
                    String time = DateUtilChange.timestamp2String(jsonModel_my.getMessagedetail().get(0).getLastUpdatedTxStamp(),DateUtilChange.DEFAULT_SECOND_FORMAT);
                    tv_message_detail_title.setText(jsonModel_my.getMessagedetail().get(0).getUserMessageTitle());
                    tv_message_detail_sender.setText(jsonModel_my.getMessagedetail().get(0).getSenderId());
                    tv_message_detail_time.setText(time);
                    tv_message_detail_context.setText(jsonModel_my.getMessagedetail().get(0).getUserMessageContent());
                }
            }

            @Override
            public void onFailure(HttpException error, String msg) {
                ToastUtils.showShort(MessageDetailsActivity.this, "网络异常！");
            }
        });

    }
    private void initview() {
        tv_message_detail_title=(TextView)findViewById(R.id.tv_message_detail_title);
        tv_message_detail_sender=(TextView)findViewById(R.id.tv_message_detail_sender);
        tv_message_detail_time=(TextView)findViewById(R.id.tv_message_detail_time);
        tv_message_detail_context=(TextView)findViewById(R.id.tv_message_detail_context);
        ll_topBack = (LinearLayout) findViewById(R.id.ll_topBack);

    }

    public void onClick(View v) {
    }

    private void setRead(){
        intent = new Intent();
        intent.putExtra("read","1");
        setResult(3,intent);
    }

}
